package mju.cxf.controller.user;


import io.swagger.annotations.Api;
import mju.cxf.result.Result;
import mju.cxf.service.ProductCategoriesService;
import mju.cxf.vo.ProductCategoryVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

@RestController
@Api(tags = "分类和商品接口列表")
@RequestMapping("/api/productAndCategory")
public class IProductAndCategoryController {
    @Autowired
    private ProductCategoriesService service;
    /**
     * U根据分类名查询商品
     * @return
     */
    @GetMapping("/productAndCategoryById")
    public Result<ProductCategoryVO> getProductsBy(@RequestParam int id) {
        return Result.success(service.getCategoriesAndProductById(id));
    }
    /**
     * U点击分类 查询所有分类和第一个分类的商品
     * @return
     */
    @GetMapping("/allProductAndCategory")
    public Result<HashMap<String,Object>> getCategoriesToProducts() {
        HashMap<String,Object> allCategoriesAndProduct = service.getAllCategoriesAndProduct();
        return Result.success(allCategoriesAndProduct);
    }

    /**
     * U点击商品进入商品列表
     * @param productId,categoriesId
     * @return ProductListVO
     */
    @GetMapping("/getProductList")
    public Result<HashMap<String,Object>> getCategoriesToProducts(@RequestParam("categoriesId") int categoriesId, @RequestParam("productId") int productId) {
        return Result.success(service.getProductsByCategoriesId(productId,categoriesId));
    }
}
